﻿<UserControl x:Class="Northwind.UI.WPF.OrderWizardOrderDetailsView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
              xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
             xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WPF4"             
             xmlns:local="clr-namespace:Northwind.UI.WPF"  
             mc:Ignorable="d" 
             d:DesignHeight="360" d:DesignWidth="650">
    <DockPanel>
        <Border DockPanel.Dock="Top" Padding="10" 
                Margin="6,6,6,0"
                CornerRadius="5"
                Background="{StaticResource mainBlueBrush}">
            <TextBlock Text="Enter Order Details"
                    Foreground="White" FontWeight="Bold"
                    FontSize="16"
                    HorizontalAlignment="Center"  />
        </Border>
        <Grid Margin="5,3,5,10">
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="auto" />
            </Grid.RowDefinitions>

            <StackPanel Grid.Row="0">
                <Grid>
                    <Grid.ColumnDefinitions >
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="auto" />
                    </Grid.ColumnDefinitions>
                    <GroupBox Header="Order" Grid.Column="0">
                        <Grid Margin="4">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="6" />
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="*" />
                            </Grid.RowDefinitions>
                            <Label Content="Order Date:" Grid.Row="0" Grid.Column="0" 
                                     HorizontalAlignment="Right" />
                            <TextBox Text="{Binding Path=OrderDate, Mode=OneWay,
                                     UpdateSourceTrigger=PropertyChanged}" Grid.Row="0" 
                                     Grid.Column="2" />
                            <Label Content="Shipped Date:" Grid.Row="1" Grid.Column="0" 
                                     HorizontalAlignment="Right" />
                            <TextBox Text="{Binding Path=ShippedDate, Mode=OneWay,
                                     UpdateSourceTrigger=PropertyChanged}" Grid.Row="1" 
                                     Grid.Column="2" />
                            <Label Content="Freight:" Grid.Row="2" Grid.Column="0"
                                     HorizontalAlignment="Right" />
                            <TextBox Text="{Binding Path=Freight, Mode=OneWay,
                                     UpdateSourceTrigger=PropertyChanged}" Grid.Row="2" 
                                     Grid.Column="2" />
                            <Label Content="Order Total $:" Grid.Row="3" Grid.Column="0" 
                                     HorizontalAlignment="Right" />
                            <TextBox Text="{Binding Path=Total, Mode=OneWay,
                                     UpdateSourceTrigger=PropertyChanged}" Grid.Row="3" IsEnabled="False"
                                     Grid.Column="2" />
                        </Grid>
                    </GroupBox>
                    <Expander Grid.Column="1" ExpandDirection="Left" IsExpanded="False">
                        <Expander.Header>
                            <TextBlock Text="Add Details" FontSize="14" FontWeight="Bold">
                                    <TextBlock.LayoutTransform>
                                        <RotateTransform Angle="90" />
                                    </TextBlock.LayoutTransform>
                            </TextBlock>
                        </Expander.Header>
                        <StackPanel Width="250" Margin="4">
                            <Border Background="LightGray">
                                <Grid Margin="4" DataContext="{Binding TempOrderDetail}">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="Auto" />
                                        <ColumnDefinition Width="6" />
                                        <ColumnDefinition Width="*" />
                                    </Grid.ColumnDefinitions>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto" />
                                        <RowDefinition Height="Auto" />
                                        <RowDefinition Height="Auto" />
                                        <RowDefinition Height="Auto" />
                                        <RowDefinition Height="Auto" />
                                    </Grid.RowDefinitions>
                                    <Label Content="Product:" Grid.Row="0" Grid.Column="0"
                                             HorizontalAlignment="Right" />
                                    <!--<TextBox Text="{Binding Path=Order.Customer.CompanyName, 
                                             UpdateSourceTrigger=PropertyChanged}" Grid.Row="0"
                                             Grid.Column="2" />-->
                                    <ComboBox ItemsSource="{Binding ProductsList}"
                                                  SelectedItem="{Binding SelectedProduct}"
                                                  DisplayMemberPath="ProductName" 
                                                  Grid.Row="0" Grid.Column="2"/>
                                    <Label Content="Quantity:"
                                             Grid.Row="1"
                                             HorizontalAlignment="Right" />
                                    <TextBox Text="{Binding Quantity, 
                                             UpdateSourceTrigger=PropertyChanged}"
                                             Grid.Row="1"
                                             Grid.Column="2" />
                                    <Label Content="Unit Price:"
                                             Grid.Row="2"
                                             HorizontalAlignment="Right" />
                                    <TextBox Text="{Binding UnitPrice, 
                                             UpdateSourceTrigger=PropertyChanged}"
                                             Grid.Row="2"
                                             Grid.Column="2" />
                                    <Label Content="Discount:"
                                             Grid.Row="3"
                                             HorizontalAlignment="Right" />
                                    <TextBox Text="{Binding Discount, 
                                             UpdateSourceTrigger=PropertyChanged}"
                                             Grid.Row="3"
                                             Grid.Column="2" />
                                </Grid>
                            </Border>
                            <Button HorizontalAlignment="Center" Width="40"  Margin="4"
                                        Content="+" Command="{Binding AddOrderDetail}" />
                        </StackPanel>
                    </Expander>
                </Grid>
                <GroupBox Header="Order Details"  Margin="0,4,0,0" MinHeight="100">
                    <StackPanel>
                        <ListView Margin="0,4,0,0"  ItemsSource="{Binding OrderDetails}" Grid.Row="4" Grid.ColumnSpan="3" >
                            <ListView.Resources>
                                <Style TargetType="ListViewItem">
                                    <Setter Property="HorizontalContentAlignment"
                                Value="Stretch" />
                                </Style>
                            </ListView.Resources>
                            <ListView.View>
                                <GridView>
                                    <GridView.Columns>
                                        <GridViewColumn Header="Product">
                                            <GridViewColumn.CellTemplate>
                                                <DataTemplate>
                                                    <TextBlock TextAlignment="Left"
                                                   Text="{Binding Product.ProductName}"  />
                                                </DataTemplate>
                                            </GridViewColumn.CellTemplate>
                                        </GridViewColumn>
                                        <GridViewColumn Header="Quantity">
                                            <GridViewColumn.CellTemplate>
                                                <DataTemplate>
                                                    <TextBlock TextAlignment="Center"
                                                   Text="{Binding Quantity}"  />
                                                </DataTemplate>
                                            </GridViewColumn.CellTemplate>
                                        </GridViewColumn>
                                        <GridViewColumn Header="UnitPrice">
                                            <GridViewColumn.CellTemplate>
                                                <DataTemplate>
                                                    <TextBlock TextAlignment="Center" 
                                                   Text="{Binding UnitPrice, StringFormat='{}{0:C}'}" />
                                                </DataTemplate>
                                            </GridViewColumn.CellTemplate>
                                        </GridViewColumn>
                                    </GridView.Columns>
                                </GridView>
                            </ListView.View>
                        </ListView>
                    </StackPanel>
                </GroupBox>
            </StackPanel>   
            <StackPanel Grid.Row="1">
                <DockPanel>
                    <Button DockPanel.Dock="Left" Content="Back" Command="{Binding ShowPreviousWizardChild}" 
                            Width="50" HorizontalAlignment="Right" Margin="10,0,10,0" />
                    <Button DockPanel.Dock="Right" Content="Finish" Command="{Binding ShowNextWizardChild}" 
                            Width="50" HorizontalAlignment="Right" Margin="0,0,10,0" />
                </DockPanel>
            </StackPanel>            
        </Grid>
    </DockPanel>
</UserControl>
